package principle.lawOfDemeter.origin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;


/**
 * @author： pang-yun
 * @date： 2021-08-25 13:15
 * 功能目的 ：用于 管理所有的老师和 学生
 */

public class Principal {
    private Teacher teacher = new Teacher("Demeter", "1601");


    // 查询 班级的 信息  总分 人数 平均分
    public Map<String ,Object> queryClazzInfo(String clazz){
        // 根据下面方法获取 相关信息
        double totalScore=clazzTotalScore();
        double averageClazzScore = averageScore();
        double studentCount= clazzStudentCount();

        //组装对象
        HashMap<String, Object> map = new HashMap<>();
        map.put("班级",teacher.getClazz());
        map.put("老师姓名",teacher.getName());
        map.put("totalScore",totalScore);
        map.put("average",averageClazzScore);
        map.put("studentcount",studentCount);
        return map;

    }

    //查询总分
    public double clazzTotalScore() {
        List<Student> studentList = Teacher.getStudentList();
        Optional<Double> reduce = studentList.stream().map(a -> a.getGrade()).reduce((x, y) -> x + y);
        return reduce.get();
    }

    //平均分
    public double averageScore(){
        List<Student> studentList = Teacher.getStudentList();
        Double collect = studentList.stream().collect(Collectors.averagingDouble(Student::getGrade));
        return collect;
    }

    // 返回班级人数
    public int clazzStudentCount(){
        return Teacher.getStudentList().size();
    }

}
